<?php

namespace App\Listeners;

use App\Events\UserRegisterEvent;
use App\Models\Category;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

class CategoryStoreListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  UserRegisterEvent  $event
     * @return void
     */
    public function handle(UserRegisterEvent $event)
    {
        $user = $event->user;

        // 新增默认分类
        $user->category()->create([
            'category_name' => Category::CATEGORY_DEFAULT_NAME
        ]);
    }
}
